package net.gillessed.icarus.swingui.color;

import java.awt.Dimension;
import java.util.Map;

import javax.swing.JComboBox;
import javax.swing.JPanel;

import net.gillessed.icarus.FlameModel;

public class PredefinedGradientPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	
	private final JComboBox comboBox;

	public PredefinedGradientPanel(FlameModel model, Map<String, Gradient> gradientMap) {
		Gradient[] gradients = new Gradient[gradientMap.size()];
		int i = 0;
		int selectedValue = -1;
		for(Gradient g : gradientMap.values()) {
			gradients[i] = g;
			if(g.getName().equals(model.getColorProvider().getGradient().getName())) {
				selectedValue = i;
			}
			i++;
		}
		comboBox = new JComboBox(gradients);
		GradientCellRenderer cellRenderer = new GradientCellRenderer();
		cellRenderer.setPreferredSize(new Dimension(Gradient.DEFAULT_SIZE, 30));
		comboBox.setRenderer(cellRenderer);
		comboBox.setSelectedItem(gradients[selectedValue]);
		add(getComboBox());
	}
	
	public Gradient getChosenGradient() {
		return (Gradient)getComboBox().getSelectedItem();
	}

	public JComboBox getComboBox() {
		return comboBox;
	}
}
